﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_DSJCJ.BLL
{
    /// <summary>
    /// 系统配置主表 逻辑类
    /// </summary>
    public class Config
    {
        /// <summary>
        /// 系统配置主表数据类
        /// </summary>
        private DAL.Config configDAL = new DAL.Config();

        /// <summary>
        /// 构造函数
        /// </summary>
        public Config()
        {
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-09-03</date>
        /// </summary>
        /// <param name="keyName">关键字</param>
        /// <param name="configClass">配置类别</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public Model.Config GetModel(string keyName, string configClass, string entityNo)
        {
            return configDAL.GetModel(keyName, configClass, entityNo);
        }
        
        /// <summary>
        /// 获得全部启用的数据列表
        /// <creator>wangl</creator>
        /// <date>2013-09-03</date>
        /// </summary>
        /// <param name="configClass">配置类别</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>列表</returns>
        public List<Model.Config> GetListAllIsUse(string entityNo)
        {
            DataSet ds = configDAL.GetListAllIsUse( entityNo);
            return DataTableToList(ds.Tables[0]);
        }
        
        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-09-03</date>
        /// </summary>
        /// <param name="dt">DataTable对象</param>
        /// <returns>列表</returns>
        private List<ElingOA6_DSJCJ.Model.Config> DataTableToList(DataTable dt)
        {
            List<ElingOA6_DSJCJ.Model.Config> modelList = new List<ElingOA6_DSJCJ.Model.Config>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ElingOA6_DSJCJ.Model.Config model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = configDAL.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
    }
}
